<template>
  <div id="app">
    <el-form :model="loginForm" ref="loginFormRef" label-width="80px" class="login-container">
      <h1 class="title">视频网站登录</h1>
      <el-form-item label="用户名" prop="username">
        <el-input v-model="loginForm.username"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input type="password" v-model="loginForm.password"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleLogin">登录</el-button>
        <el-button @click="resetForm">重置</el-button>
        <el-button type="text" @click="$router.push('/register')">
          没有账号？立即注册
        </el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      loginForm: {
        username: '',
        password: ''
      }
    };
  },
  methods: {
    handleLogin() {
      this.$refs.loginFormRef.validate((valid) => {
        if (valid) {
          // 模拟登录成功
          localStorage.setItem('token', 'dummy-token')
          this.$router.push('/menu') // 跳转到菜单页
        }
      });
    },
    resetForm() {
      this.$refs.loginFormRef.resetFields();
    }
  }
};
</script>

<style scoped>
.login-container {
  width: 300px;
  margin: 100px auto;
  padding: 20px;
  border: 1px solid #ccc;
  border-radius: 5px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

.title {
  text-align: center;
  margin-bottom: 20px;
}
</style>